﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;

namespace MapControl.Misc
{
    public class MediumSquareCoord : SquareCoord
    {
        private SquareCoord bigSquare;
        private SquareCoord basicSquare;

        public MediumSquareCoord(RectangleF rect, int colNum, int rowNum, SquareCoord parent)
            : base(rect, colNum, rowNum, parent)
        {
            basicSquare = parent;
            bigSquare = basicSquare.parentSquareCoord;
        }

        /// <summary>
        /// Draw Medium BorderSquare
        /// </summary>
        /// <param name="g"></param>
        /// <param name="width"></param>
        public override void Draw(Graphics g, float width)
        {
            Pen pen = new Pen(Color.Orange, width);
            pen.DashStyle = DashStyle.Dash;
            int totalX = NumOfColumns * basicSquare.NumOfColumns * bigSquare.NumOfColumns;
            int totalY = NumOfRows * basicSquare.NumOfRows * bigSquare.NumOfRows;

            //Vẽ các trục giữa
            for (int i = 1; i < totalX; i++)
                g.DrawLine(pen, bigSquare.BorderSquare.X + Width * i, bigSquare.BorderSquare.Y, bigSquare.BorderSquare.X + Width * i, bigSquare.BorderSquare.Y + bigSquare.BorderSquare.Size.Height);

            //Vẽ các trục ngang
            for (int i = 1; i < totalY; i++)
                g.DrawLine(pen, bigSquare.BorderSquare.X, bigSquare.BorderSquare.Y + Height * i, bigSquare.BorderSquare.X + bigSquare.BorderSquare.Size.Width, bigSquare.BorderSquare.Y + Height * i);

            pen.Dispose();
        }

        public override string GetCoord(PointF p)
        {
            string value = "";
            int X, Y;
            X = (int)((p.X - parentSquareCoord.currentSquare.X) / Width);
            Y = (int)((p.Y - parentSquareCoord.currentSquare.Y) / Height);

            //Lưu thông tin tọa độ ô vuông hiện tại
            currentSquare = new RectangleF(parentSquareCoord.currentSquare.X + X * Width, parentSquareCoord.currentSquare.Y + Y * Height, Width, Height);

            value = MediumSquareArray[X][Y].ToString();
            return value;
        }
    }
}
